import os
from flask import Flask, Blueprint, render_template, send_from_directory, request
from apps.common.utils import get_active_theme_name
# 获取当前文件所在目录
current_dir = os.path.dirname(os.path.abspath(__file__))

# 创建ppress view
ppress_bp = Blueprint('ppress',
                    __name__,
                    url_prefix='/ppress',
                    template_folder='templates')

@ppress_bp.route('/')
def index():
    """ppress主题首页"""
    return render_template(get_active_theme_name() + '/index.html', title='PPress主题首页')

@ppress_bp.route('/about')
def about():
    """ppress主题关于页面"""
    return render_template(get_active_theme_name() + '/about.html', title='关于PPress')

@ppress_bp.route('/static/<path:filename>')
def static_files(filename):
    """ppress主题静态文件"""
    static_folder = os.path.join(current_dir, 'static')
    return send_from_directory(static_folder, filename)

def init(app: Flask = None):
    """初始化ppress主题视图"""
    print("ppress view initialized")
    if app:
        print(f"Flask app: {app.name}")

def unload(app: Flask = None):
    """卸载ppress主题视图"""
    print("ppress view unloaded")